package 力扣._00周赛._369周赛.问题2;

public class Solution {
    public long minSum(int[] nums1, int[] nums2) {
        long sum1 = 0, sum2 = 0, c1_0 = 0, c2_0 = 0;
        for (int i : nums1) {
            sum1 += i;
            if (i == 0)
                c1_0++;
        }
        for (int i : nums2) {
            sum2 += i;
            if (i == 0)
                c2_0++;
        }
        if (c1_0 == 0 && c2_0 == 0)
            return sum1 == sum2 ? sum1 : -1;
        if (c1_0 == 0) {
            if (sum2 + c2_0 > sum1)
                return -1;
            else
                return sum1;
        }
        if (c2_0 == 0) {
            if (sum1 + c1_0 > sum2)
                return -1;
            else
                return sum2;
        }
        //两个都可以加
        return Math.max(sum2 + c2_0, sum1 + c1_0);

    }
}
